﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="aaagctrl.js" />
/// <reference path="SBT.debug.js" />
Manager = function(host)
{
    Manager.initializeBase(this,[host]);
}

Manager.prototype = 
{
    onSilverlightLoaded : function(slControl, args)
    {
        var plugin = this.get_plugin();
        var content = plugin.Content;
        var downloader = plugin.createObject("downloader");
        var mgr = this;
        
        downloader.addEventListener("completed", function()
        {
            var composedScroller = new SBT.ComposedScroller();
            var downTpl = downloader.getResponseText("ButtonDown.xaml");
            var upTpl = downloader.getResponseText("ButtonUp.xaml");
            var enterTpl = downloader.getResponseText("ButtonEnter.xaml");
            var leaveTpl = downloader.getResponseText("ButtonLeave.xaml");
            var left = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("btnLeft"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var leftPage = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("pageLeft"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var right = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("btnRight"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var rightPage = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("pageRight"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var top = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("btnUp"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var topPage = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("pageUp"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var bottom = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("btnDown"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            var bottomPage = $create(SBT.Button,{plugin:plugin,
                    element:content.findName("pageDown"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            
            var bottomBar =$create(SBT.Button,{plugin:plugin,
                    element:content.findName("bottomBar"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            $create(SBT.Grid,{plugin:plugin,
                    element:content.findName("bottomBar")},null,null,null);
                    
            var bottomGrid = $create(SBT.Grid,{plugin:plugin, element:content.findName("bottomGrid")},null,null,null);
            var rightBar =$create(SBT.Button,{plugin:plugin,
                    element:content.findName("rightBar"),
                    mouseDownTemplate:downTpl,
                    mouseUpTemplate:upTpl,
                    mouseEnterTemplate:enterTpl,
                    mouseLeaveTemplate:leaveTpl},null,null,null);
            $create(SBT.Grid,{plugin:plugin,
                    element:content.findName("rightBar")},null,null,null);        
            var rightGrid = $create(SBT.Grid,{plugin:plugin, element:content.findName("rightGrid")},null,null,null);
            
            var horScroll = new SBT.HorizontalScrollBar();
            horScroll.set_minusBtn(left);
            horScroll.set_plusBtn(right);
            horScroll.set_bar(bottomBar);
            horScroll.set_barContainer(bottomGrid);   
           
            var verScroll = new SBT.VerticalScrollBar();
            verScroll.set_minusBtn(top);
            verScroll.set_plusBtn(bottom);
            verScroll.set_bar(rightBar);
            verScroll.set_barContainer(rightGrid); 
            
            var horScrollPage = new SBT.HorizontalPageFlipScroller();
            horScrollPage.set_leftButton(leftPage);
            horScrollPage.set_rightButton(rightPage);
            
            var verScrollPage = new SBT.VerticalPageFlipScroller();
            verScrollPage.set_bottomButton(bottomPage);
            verScrollPage.set_topButton(topPage);
            
            composedScroller.set_scrollers([horScroll,verScroll,verScrollPage,horScrollPage]);
            var scrollContent = $create(SBT.AgBehavior,{plugin:plugin, element:content.findName("scrollContent")},null,null,null);
            var scrollContainer = $create(SBT.ScrollContainer,{plugin:plugin, element:content.findName("scrollContainer"),content:scrollContent,scroller : composedScroller},null,null,null);
        });
        
        downloader.open("GET", "Templates.zip");
        downloader.send();
    }
}


Manager.registerClass("Manager", SBT.SLManager);